#include "jing.h"

jing::jing()
{
    setWindowTitle("报警日志");
    this->resize(900,450);
    QVBoxLayout *vbox =new QVBoxLayout(this);

    table =new QTableWidget;
    table->setSelectionBehavior(QAbstractItemView::SelectRows);
    table->setEditTriggers(QAbstractItemView::CurrentChanged);
    table->setColumnCount(7);
    table->setHorizontalHeaderLabels(QStringList()<<"异常时间"<<"名称"<<"所在地"<<"温度"<<"湿度"<<"异常等级"<<"类型");

    vbox->addWidget(table);
}

void jing::getdata(QString name, QString address, QString wendu, QString shidu, QString dengji,QString leixing)
{
    int irow =table->rowCount();
    table->setRowCount(irow+1);
    table->setItem(irow,0,new QTableWidgetItem(QDateTime::currentDateTime().toString ("yyyy-MM-dd hh:mm")));
    table->setItem(irow,1,new QTableWidgetItem(name));
    table->setItem(irow,2,new QTableWidgetItem(address));
    table->setItem(irow,3,new QTableWidgetItem(wendu));
    table->setItem(irow,4,new QTableWidgetItem(shidu));
    table->setItem(irow,5,new QTableWidgetItem(dengji));
    table->setItem(irow,6,new QTableWidgetItem(leixing));
    if(leixing == "停电")
    {
        table->item(irow, 5)->setBackground(Qt::red);
    }
    else{
        table->item(irow, 5)->setBackground(Qt::blue);
    }
}
